//? 参数可能包含函数、正则、日期、ES6新对象

function shallowClone(target) {
    if (typeof target === "object" && target !== null) {
        const constructor = target.constructor
        const reg = /^(Function|RegExp|Date|Map|Set)$/i
        //? 对参数的构造函数名称进行正则
        if (reg.test(constructor.name)) {
            return target
        }
        let obj = Array.isArray(target) ? [] : {}
        for (let i in target) {
            if(target.hasOwnProperty(i)) {
                obj[i] = target[i]
            }
        }
        return obj
    }
    else {
        return target
    }
}
const obj = {name: 'John', age: 25}
const clonedObj = shallowClone(obj)
console.log(clonedObj) // {name: 'John', age: 25}
console.log(clonedObj === obj) // false
